package com.woniuxy.secondhand.controller;


import com.woniuxy.life.core.api.CommonResult;
import com.woniuxy.secondhand.entity.SecComplain;
import com.woniuxy.secondhand.service.SecComplainService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 二手产品投诉 前端控制器
 * </p>
 *
 * @author chaohuijiang
 * @since 2020-09-24
 */
@RestController
@RequestMapping("/secondhand/sec-complain")
public class SecComplainController {
    @Resource
    SecComplainService secComplainService;
    //添加投诉
    @RequestMapping("/insert")
    public CommonResult<SecComplain> insert(SecComplain secComplain){
        secComplainService.save(secComplain);
        return CommonResult.success();
    }
    //撤销投诉
    @RequestMapping("/delete/{complainId}")
    public CommonResult<SecComplain> delete(@PathVariable("complainId") Integer complainId){
        secComplainService.removeById(complainId);
        return CommonResult.success();
    }
    //查询所有投诉内容
    @RequestMapping("/findall")
    public ModelAndView findll(){
        ModelAndView mv=new ModelAndView();
        List<SecComplain> secComplains=secComplainService.list();
        mv.addObject("secComplains",secComplains);
        //转发到消息页面
        mv.setViewName("message");
        return mv;
    }

}
